package com.alibaba.nacos.controller;

/**
 * @program: nacos-spring-cloud-example
 * @description: 测试微服务功能控制器
 * @author: coderChen
 * @create: 2024-09-29 11:07
 **/
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class TestController {
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    ProviderService providerService;

//    http://localhost:8082/consumer/{str}
    @GetMapping("/consumer/hello/{str}")
    public String echo(@PathVariable String str) {
        return restTemplate.getForObject("http://service-provider/echo/{str}", String.class,str);
    }

    /*
    * Openfeign
    */

    @GetMapping("/consumer/openfeign")
    public String hiOpenfeign(){
        String providerBack = providerService.hello();
        return "consumer is here. " + providerBack;
    }

    @GetMapping("/consumer/timeOut")
    public String requestTimeOut(){
        String providerBack = providerService.requestTimeOut();
        return "consumer is here. " + providerBack;
    }

}
